<?php

namespace Index;

use C\L\WebController;

const EVENT_ENUM = [
  'activate',
  'register',
];

class ChannelController extends WebController
{
    public function reportAction()
    {
        $event = $this->request->getQuery('event', 'string', null);
        $imei  = $this->request->getQuery('imei', 'string', null);
        $oaid  = $this->request->getQuery('oaid', 'string', null);

        if (!in_array($event, EVENT_ENUM)) {
            return $this->error('未知事件');
        }

        $channelLog = $this->s_channel->match($oaid, $imei);

        if (!$channelLog) {
            return $this->error('未匹配到渠道记录');
        }

        $this->s_channel->report($channelLog, 'activate');

        $this->success($channelLog);
    }
}
